package com.game.majiang.vo;

import java.sql.Types;

import javax.sql.rowset.CachedRowSet;

import com.game.server.db.Parameter;
import com.game.server.db.ParameterType;
import com.game.server.db.SqlHelper;
import com.game.server.db.SqlHelperwrite;

public class TableHuikanVo {
	/**
	 * 
	 * @param roomNumber
	 * @param shoushu								（是否开牌）     											（发了几张牌）	(是否然牌)
	 * @param plString   uid=11,nickname=22,head=33,kaipai=44,cards=55,zupai=66,mangguo=77,bet=88,win=99,count=1010,ranpai=1111;
	 * 
	 *                   zupai=1|2|3|4|5  cards=1|2|3|4|5
	 */
	public static void Addtablehuikan(int roomNumber,int shoushu,String plString) {
		 String sql = "INSERT INTO tablehuikan (roomNumber,shoushu,neirong) VALUES (?,?,?)";
		 Parameter p1 = new Parameter(Types.INTEGER, roomNumber, ParameterType.Input);
		 Parameter p2 = new Parameter(Types.INTEGER, shoushu, ParameterType.Input);
		 Parameter p3 = new Parameter(Types.VARCHAR, plString, ParameterType.Input);
		 SqlHelperwrite.execute(sql,p1,p2,p3);
	}
	
	
	public static int Paijuhuikancount(int tableid) {
		int i=0;
		String cmdText1 = "select count(id) from tablehuikan where roomNumber="+tableid+"";
		CachedRowSet rs = SqlHelper.getResultSet(cmdText1);
		try {
			if (rs.next()) {
				i=rs.getInt(1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return i; 
	}
	
	public static void Saveuserloveback(String loveback,int uid)
	{
		String cmdText = "update users set loveback='"+loveback+"' where id = "+uid+"";
		
		SqlHelperwrite.execute(cmdText);
	   
	}
	
	public static String lovebackcount1(int uid) {
		String  a="";
		String cmdText1 = "select loveback from users where id="+uid+"";
		CachedRowSet rs = SqlHelper.getResultSet(cmdText1);
		try {
			if (rs.next()) {
				a=rs.getString(1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return a; 
	}
	public static String Paijuhuikanstring(int tableid,int shoushu) {
		String string="";
		String cmdText1 = "select neirong from tablehuikan where roomNumber="+tableid+" and shoushu="+shoushu+"";
		CachedRowSet rs = SqlHelper.getResultSet(cmdText1);
		try {
			while (rs.next()) {
				string=rs.getString(1);
				
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return string; 
	}
	
	public static void addlovepailog(int roomNumber,int shoushu,int  uid,String time,int winlose,int difen,int playtype,int gamechang,int gametime) {
		 String sql = "INSERT INTO lovepailog (tableid,shoushu,uid,time,winlose,difen,playtype,gamechang,gametime) VALUES (?,?,?,?,?,?,?,?,?)";
		 Parameter p1 = new Parameter(Types.INTEGER, roomNumber, ParameterType.Input);
		 Parameter p2 = new Parameter(Types.INTEGER, shoushu, ParameterType.Input);
		 Parameter p3 = new Parameter(Types.INTEGER, uid, ParameterType.Input);
		 Parameter p4 = new Parameter(Types.VARCHAR, time, ParameterType.Input);
		 Parameter p5 = new Parameter(Types.INTEGER, winlose, ParameterType.Input);
		 Parameter p6 = new Parameter(Types.INTEGER, difen, ParameterType.Input);
		 Parameter p7 = new Parameter(Types.INTEGER, playtype, ParameterType.Input);
		 Parameter p8 = new Parameter(Types.INTEGER, gamechang, ParameterType.Input);
		 Parameter p9 = new Parameter(Types.INTEGER, gametime, ParameterType.Input);
		 SqlHelperwrite.execute(sql,p1,p2,p3,p4,p5,p6,p7,p8,p9);
	}
	
	public static boolean deletelovepailog(int roomNumber,int shoushu,int  uid){
		String cmdText = "DELETE FROM lovepailog WHERE  tableid="+roomNumber+" and shoushu="+shoushu+" and uid="+uid+"";
		Object obj=SqlHelperwrite.execute(cmdText);
		return (int)obj>0;
	}
}
